﻿// 
// $Id: _FormWidget.cs 3981 2010-11-02 11:12:16Z unknown $
// 
// Zen UI Toolkit Copyright (c) 2010, Paul Clancy.  All rights reserved.
// 
// Redistribution and use in source and binary forms, with or without modification, are permitted provided 
// that the following conditions are met:
// 
// * 	Redistributions of source code must retain the above copyright notice, this list of 
// 	conditions and the following disclaimer.
// 
// * 	Redistributions in binary form must reproduce the above copyright notice, this list of 
// 	conditions and the following disclaimer in the documentation and/or other materials 
// 	provided with the distribution.
// 
// * 	Neither the name of AppTek nor the names of its contributors may be used to endorse 
// 	or promote products derived from this software without specific prior written permission.
// 
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND 
// ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 
// OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 
// THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 
// HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, 
// OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 
// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
// 

#region

using System.ComponentModel;
using System.Web.UI;
using System.Web.UI.WebControls;

#endregion

namespace Zen.Toolkit
{
    [DojoRequires(ModuleName = "dijit.form.Form")]
    public abstract class FormWidget : WidgetBase, IPopper
    {
        protected FormWidget(HtmlTextWriterTag tag) : base(tag)
        {
        }

        [DojoProperty(Name = "alt")]
        [DefaultValue("Corresponds to the native HTML <input> element's attribute")]
        public string Alt
        {
            get { return (string) ViewState["Alt"] ?? ""; }
            set { ViewState["Alt"] = value; }
        }

        [DojoProperty(Name = "disabled")]
        [Description("Should this widget respond to user input?")]
        [DefaultValue(false)]
        public bool Disabled
        {
            get
            {
                object o = ViewState["Disabled"];
                return (o == null) ? false : (bool) o;
            }
            set { ViewState["Disabled"] = value; }
        }

        [DojoProperty(Name = "baseClass")]
        [Description(
            "Root CSS class of the widget (ex: dijitTextBox), used to construct CSS classes to indicate widget state")]
        [DefaultValue("")]
        public string CssBaseClass
        {
            get { return (string) ViewState["CssBaseClass"] ?? ""; }
            set { ViewState["CssBaseClass"] = value; }
        }

        [DojoProperty(Name = "tabIndex")]
        [DefaultValue(0)]
        [Description("Order fields are traversed when user hits the tab key")]
        public int TabIndex
        {
            get
            {
                object o = ViewState["TabIndex"];
                return (o == null) ? 0 : (int) o;
            }
            set { ViewState["TabIndex"] = value; }
        }

        [DojoProperty(Name = "intermediateChanges")]
        [Description("Fires onChange for each value change or only on demand")]
        [DefaultValue(false)]
        public bool IntermediateChanges
        {
            get
            {
                object o = ViewState["IntermediateChanges"];
                return (o == null) ? false : (bool) o;
            }
            set { ViewState["IntermediateChanges"] = value; }
        }

        [DojoProperty(Name = "scrollOnFocus")]
        [Description("On focus, should this widget scroll into view?")]
        [DefaultValue(false)]
        public bool ScrollOnFocus
        {
            get
            {
                object o = ViewState["ScrollOnFocus"];
                return (o == null) ? false : (bool) o;
            }
            set { ViewState["ScrollOnFocus"] = value; }
        }

        [DojoStyle(Name = "width")]
        public Unit Width
        {
            get
            {
                object o = ViewState["Width"];
                return (o == null) ? Unit.Empty : (Unit) o;
            }

            set { ViewState["Width"] = value; }
        }

        [DojoStyle(Name = "height")]
        public Unit Height
        {
            get
            {
                object o = ViewState["Height"];
                return (o == null) ? Unit.Empty : (Unit) o;
            }

            set { ViewState["Height"] = value; }
        }
    }
}